<template>
  <AnalysisWrap
    titleText="模型压平"
    info="提示: 1、只支持部分模型压平(如有带着色器的)； 2、部分模型的压平可能存在异常(如缩放出现碎片现象)"
    @goAnalysisOtherViewFn="goAnalysisOtherView"
  >
    <template #container>
      <div class="control">
        <span class="lable">选择模型：</span>
        <mars-button class="btn" @click="onCheckedModel">图上选点</mars-button>
        <span class="checkModelText">{{ checkedModel }} </span>
      </div>
      <div class="control">
        <span class="lable">压平区高度：</span>
        <mars-input-number class="heightInput" v-model:value="modelFlatHeight" @change="onChangeFlatHeight" :step="1" />
        <span class="unit">米</span>
      </div>
      <div class="control-play">
        <mars-button class="btn" @click="onDrawExtent">绘制矩形</mars-button>
        <mars-button class="btn" @click="onDraw">绘制多边形</mars-button>
        <mars-button class="btn" danger @click="clearModelFlatData">清除</mars-button>
      </div>
    </template>
  </AnalysisWrap>
</template>

<script setup lang="ts">
import { onUnmounted, ref, onMounted } from "vue"
import AnalysisWrap from "./analysis-wrap.vue"
import * as mapWork from "./map"

const emit = defineEmits(["goAnalysisOtherView"])

function goAnalysisOtherView(name: string) {
  emit("goAnalysisOtherView", name)
}

onMounted(() => {
  // 以下为了演示功能，实际项目请注释
  const name = mapWork.onMountedModelFlat()
  checkedModel.value = "已选择“" + name + "”"
})

onUnmounted(() => {
  mapWork.onUnmountedModelFlat()
})

// 选择模型
const checkedModel = ref<string>("未选择")
const onCheckedModel = () => {
  mapWork.onCheckedModelFlat().then((name) => {
    checkedModel.value = name ? "已选择“" + name + "”" : "未选择"
  })
}

// 模型的压平高度
const modelFlatHeight = ref<number>(0)
const onChangeFlatHeight = () => {
  mapWork.onChangeFlatHeight(modelFlatHeight.value)
}

// 绘制矩形
const onDrawExtent = () => {
  mapWork.onDrawExtent(modelFlatHeight.value)
}
// 绘制多边形
const onDraw = () => {
  mapWork.onDraw(modelFlatHeight.value)
}

// 清除剖切的数据
const clearModelFlatData = () => {
  mapWork.clearModelFlatData()
}
</script>
<style scoped lang="less">
.control {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  .lable {
    width: 85px;
    font-size: 14px;
    text-align: center;
    color: rgba(234, 242, 255, 0.8);
  }
  .btn {
    width: 90px;
    height: 32px;
    margin-right: 10px;
  }
  .heightInput {
    width: 190px;
    height: 32px;
  }
  .checkModelText {
    color: rgba(234, 242, 255, 0.6);
  }
  .unit {
    display: inline-block;
    margin-left: 10px;
    color: rgba(234, 242, 255, 0.6);
  }
}

.control-play {
  display: flex;
  .btn {
    flex: 1;
    &:nth-child(n + 2) {
      margin-left: 4px;
    }
  }
}
</style>
